package com.pig4cloud.pig.homecenter.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.pig4cloud.pig.homecenter.enums.OnOff;

import java.io.IOException;


public class CustomOnOffDeserializer extends JsonDeserializer<OnOff> {

	@Override
	public OnOff deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
		String value = p.getValueAsString();
		if (value == null) {
			return null;
		}
		try {
			return OnOff.valueOf(value);
		} catch (IllegalArgumentException e) {
			throw new IOException("Cannot deserialize OnOff from " + value);
		}
	}
}
